// pages/orderdetail/orderdetail.js
var app = getApp();
/**
 * _PAGE_API 常量，详情页面接口集合，对象类型
 * 请求不同页面时，根据 orderType 作为 _PAGE_API对象 的 key, 去获取 对应的value 作为 插件页面的 接口
 * @key {string} - 插件页面的 orderType值， 建议为$route.params.orderType的值
 * @value {string}  - orderType对应的插件接口
 */
const _PAGE_API = {
  shop: "order.detail", //商城默认接口
  cashier: "plugin.store-cashier.frontend.Order.detail",
  store: "plugin.store-cashier.frontend.store.order-detail",
  supplier: "plugin.supplier.frontend.order.detail",
  hotel: "plugin.hotel.frontend.hotel.detail",
  hotel_center: "plugin.hotel.frontend.hotel.center.order-detail",
  hotelcashier: "plugin.hotel.frontend.Order.detail",
  lease_toy: "plugin.lease-toy.api.order.order-detail.index",
  serviceReplenish: "plugin.service-station.frontend.order-detail.index",
  groups: "plugin.fight-groups.frontend.controllers.detail.index", //拼团
  ywmgroups: "plugin.ywm-fight-groups.frontend.controllers.detail.index", //拼团
  verifier: "plugin.package-deliver.frontend.clerk-order-detail.index", //自提点核销员
  package_delivery: "plugin.package-delivery.frontend.detail.index",
  pdy: "plugin.package-delivery.frontend.detail.index", //商城自提点核销员
  o2oVerifier: "plugin.package-deliver.frontend.clerk-order-detail.index", //门店自提点提货核销员，dispatch_type_id为12
  auction: "plugin.auction.api.order-detail", //拍卖
  auctioneer: "plugin.auction.api.order-detail",
  subsidiary: "plugin.subsidiary.frontend.order.detail",
  commission_activity: "plugin.commission-activity.api.activity-inquire.order-detail",
  pickup_card: "plugin.picking-card.frontend.detail",
  "picking-card-one": "plugin.picking-card-one.frontend.detail",
  groupsBuy: "plugin.together-purchase.api.index.getTogetherData",
  grabGroup: "plugin.snatch-regiment.api.index.getSnatchData",
  communityBuy: "plugin.package-deliver.frontend.order.detail.index",
  "luck-draw": "plugin.luck-draw.frontend.index.myPrizeDetail",
  newRetail: "plugin.new-retail.frontend.orderData.detail",
  warehouseTakeDelivery: "plugin.warehouse.frontend.controllers.takeDelivery.order-detail",
  warehousePurchasing: "plugin.warehouse.frontend.controllers.purchasing.order-detail",
  storeMang: "plugin.shop-assistant.frontend.order.order-detail",
  ysSystem: "plugin.ys-system.frontend.history-order.ys-detail",
  reserve_simple: "plugin.reserve-simple.frontend.reserve-order.get-detail",
  debt: "plugin.debt-shop.frontend.order-detail.index",
  community_buying: 'plugin.package-deliver.frontend.order.detail.index',
  travelAround: "plugin.travel-around.frontend.order.detail", //周边游的接口
  sachertorte: "plugin.yz-supply-cake.frontend.order.detail" //蛋糕叔叔的接口
};

Page({
  /**
   * 页面的初始数据
   */
  data: {
    language: "",
    regional: "请选择快递公司",
    filterExpressCompanys: [],
    inputExpressCompanyName: "",
    dateshow_1: false,
    orderType: "",
    order_id: "",
    options: [],
    columns: [],
    addresseeInfo: "",
    address: "",
    mobile: "",
    receiver: "",
    order_data: "",
    order_pay_id: "",
    dispatch_type_id: "",
    pay_type_id: "",
    hotel_start: "",
    hotel_end: "",
    night_day: "",
    hotel_name: "",
    //确认发货
    dialogVisible: false,
    expressName: "",
    numberName: "",
    package_deliver: {},
    showQrcode: false,
    qrcode_url: "",
    showDiyForm: false,
    diyform: {},
    jurisdiction_set: 0,
    showID: "",

    showBarter: false,
    showBarter_value: null,
    orderPayId: null,
    //消费红包
    showPacket: false,
    shrinkPacket: false,
    timer: null,
    hasPacket: false,

    showKefu: false,

    // 话费慢充
    phone_bill: {},

    customForm: [],
    refundShow: false, //退款原因
    refundText: "",

    integral: "积分",

    custom_receipt_confirmation_html:"",
    custom_receipt_confirmation_show:false,   //自定义确认收货弹窗
    custom_receipt_confirmation_btn:{}, //自定义确认收货弹窗按钮
    custom_receipt_confirmation_item:{},//自定义确认收货弹窗item

    electricity_bill_pro:{},

    oil_recharge:{},    //油卡充值
    aggregation_cps_recharge_bill:false,
    //S 申请存货弹窗
    inventoryApplyPopup: false, //存货申请弹窗
    inventoryApplyList: [], //仓库列表
    inventoryApplyRadio: null,
    //E 申请存货弹窗

    overlayShow: false, //新盲盒商品 - 弹窗
    drawShow: false, //新盲盒商品-恭喜中奖 - 弹窗
    drawType: 1 , //新盲盒商品-中奖类型
    newBlindBoxData: {}, //新盲盒商品 - 开箱数据

    //周边游订单信息
    travelAroundDetail: {}, //周边游
    aroundOrderDetatil: {}, //周边游子订单
    //蛋糕叔叔信息
    supplyCakeOrder: {},
    //兑换劵（显示/隐藏底部信息）
    show_detail_pay:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("options:::::", options);
    // 页面传参
    if (options.scene) {
      console.log("option.scene:::::", options.scene);
      console.log(decodeURIComponent(options.scene));
      let scene = decodeURIComponent(options.scene);
      if (scene) {
        //自提点插件(package-deliver)更改传参,判断没有格式自提点的取参
        if(scene.indexOf('&') == -1){ 
          this.packageDeliver_codeScene(scene)
        }else{
          console.log('213pd')
          var info_arr = [];
          info_arr = scene.split("&");
          for (let i = 0; i < info_arr.length; i++) {
            let chil_arr = [];
            chil_arr = info_arr[i].split("=");
            console.log(chil_arr);
            // 这是自提点
            if (chil_arr[0] == "orderType") {
              this.setData({
                orderType: chil_arr[1],
              });
            } else {
              if(this.data.orderType != 'verifier'){
                // 这是门店
                this.setData({
                  orderType: "store",
                });
              }
            }
            if (chil_arr[0] == "id") {
              this.setData({
                order_id: chil_arr[1],
              });
            } else if (chil_arr[0] == "mid") {
              app._setMid(chil_arr[1]);
            } else if (chil_arr[0] == "is_clerk") {
              this.setData({
                is_clerk: chil_arr[1],
              });
            } else if (chil_arr[0] == "cl") {
              // is_clerk 的缩写，防止二维码参数长度超出
              this.setData({
                is_clerk: chil_arr[1],
              });
            } else if(chil_arr[0] == "Q"){
              app.globalData.STORE_ID = chil_arr[1]
            }else {
              console.log("error:: 核销员进入错误");
              wx.hideLoading();
            }
          }
        }
        console.log(this.data.order_id);
      }
    } else {
      if (options.order_id) {
        this.setData({
          order_id: options.order_id,
        });
      }
      if(options.debt_shop_member_type){
        this.setData({
          debt_shop_member_type:options.debt_shop_member_type
        })
      }
      if (options.orderType && options.orderType == "groups") {
        this.setData({
          orderType: "groups",
        });
      } else if (options.orderType) {
        this.setData({
          orderType: options.orderType,
        });
      } else {
        this.setData({
          orderType: "shop",
        });
      }
    }
    if (options.order_id) {
      this.setData({
        order_id: options.order_id,
      });
    }
    if(options.keywork){
      this.setData({
        keywork:options.keywork
      })
    }
    if(options.memberId){
      this.setData({
        memberId:options.memberId
      })
    }
    if(options.show_detail_pay == 0){
      this.setData({show_detail_pay:0})
    }
    let yz_basic_info = wx.getStorageSync('yz_basic_info');
    this.setData({
      showDiyForm: false,
      vip_show:yz_basic_info.globalParameter.vip_show?yz_basic_info.globalParameter.vip_show:false 
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    let language = wx.getStorageSync("langIndex");
    this.setData({ language: language.en });
    const value = wx.getStorageSync("integral");
    if (value) {
      this.setData({
        integral: value,
      });
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getNetData();
    this.setData({
      showPacket: false,
      shrinkPacket: false,
      timer: null,
      hasPacket: false,
    });
    let basicinfo = wx.getStorageSync("yz_basic_info");
    if (basicinfo && basicinfo.globalParameter.consume_red_packet_status == 1) {
      this.checkoutConsumePacket();
    }
  },

  toUrl(e) {
    let _data = e.currentTarget.dataset || {};
    this.wxRouterLink(_data);
  },
  wxRouterLink(_data) {
    let _Param = "";
    const { url, ...otherParam } = _data;
    Object.keys(otherParam).forEach(function (key) {
      if (otherParam[key] !== "") _Param += key + "=" + otherParam[key] + "&";
    });
    if (url === "") return;
    wx.navigateTo({
      url: url + "?" + _Param.slice(0, -1),
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  // 自提点插件(package-deliver)更改传参
  packageDeliver_codeScene(scene){
    // 自提点 二维码传参更改 ,号分割 1是这次改自提点插件标识（后面可去掉）,2原来有的标识，3门店独立模板开启用的门店id 
    let sceneArr = scene.split(',');
    for(let i =0;i<sceneArr.length;i++){
      // if(sceneArr[i] == 'pd'){
        this.setData({
          order_id: sceneArr[0],
        });
        if(sceneArr[1] != 'verifier'){
          // 这是门店
          this.setData({
            orderType: "store",
          });
        }else{
          this.setData({
            orderType:sceneArr[1]
          })
        }
        if(sceneArr[2]){
          this.app.globalData.STORE_ID = sceneArr[2];
        }
      // }
    }
  },
  callPhone() {
    wx.makePhoneCall({
      phoneNumber: this.data.service_mobile,
    });
  },
  phoneClick({target:{dataset:{phone}}}){
    wx.makePhoneCall({
      phoneNumber:phone,
      success(){},
      fail(){}
    })
  },
  copyMsg({target:{dataset:{msg}}}){
    console.log(msg);
    wx.setClipboardData({
      data: msg,
      success: function (res) {
        wx.showToast({
          title: '复制成功',
          icon: 'success',
          duration: 2000
        });
      },
      fail(){
        wx.showToast({
          title: '复制失败',
          icon: 'error',
          duration: 2000
        })
      }
    })
  },
  closePop() {
    this.setData({
      showKefu: false,
    });
  },
  showMore(e) {
    let order_sn = e.currentTarget.dataset.order.order_sn;
    if (this.data.showID == order_sn) {
      this.setData({
        showID: "",
      });
    } else {
      this.setData({
        showID: order_sn,
      });
    }
  },
  startRotate() {
    if (this.data.timer) {
      clearInterval(this.data.timer);
    }
    this.data.timer = setInterval(() => {
      this.setData({
        shrinkPacket: !this.data.shrinkPacket,
      });
    }, 150);
  },
  onClickShow() {
    this.setData({
      showPacket: true,
    });
  },
  onClickHide() {
    this.setData({
      showPacket: false,
    });
  },
  toPacket() {
    wx.navigateTo({
      url: "/packageE/ConsumePacket/ConsumePacketSuccess/ConsumePacketSuccess?order_id=" + this.data.order_id.toString(),
    });
  },
  // 消费红包
  checkoutConsumePacket() {
    let urlStr = app.getNetAddresss("plugin.consume-red-packet.Frontend.Modules.Packet.Controllers.has.index");
    app._postNetWork({
      url: urlStr,
      data: {
        order_id: this.data.order_id.toString().split(","),
      },
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          this.setData({
            hasPacket: true,
          });
          this.startRotate();
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },

  // 获取客服
  getKefu() {
    let goods_id = "";

    if (this.data.order_data.has_many_order_goods.length > 0) {
      goods_id = this.data.order_data.has_many_order_goods[0].goods_id;
    }
    let urlStr = app.getNetAddresss("goods.customer-service.index");
    app._postNetWork({
      url: urlStr,
      data: {
        goods_id: goods_id,
      },
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          this.setData({
            customer_open: res.data.hasOwnProperty('customer_open')?res.data.customer_open: true,
            showKefu: true,
            cservice: res.data.cservice,
            service_QRcode: res.data.service_QRcode,
            service_mobile: res.data.service_mobile,
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },

  showDiy(e) {
    if (e.currentTarget.dataset.from) {
      for (let i = 0; i <= e.currentTarget.dataset.from.length - 1; i++) {
        if (e.currentTarget.dataset.from[i].type == "diyriqi") {
          e.currentTarget.dataset.from[i].content = this.timestampToTime(parseInt(e.currentTarget.dataset.from[i].content) * 1000);
        }
      }
      this.setData({
        showDiyForm: true,
        diyform: e.currentTarget.dataset.from,
      });
    }
  },
  timestampToTime(timestamp) {
    var date = new Date(timestamp * 1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
    let Y = date.getFullYear() + "-";
    let M = (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + "-";
    let D = this.change(date.getDate()) + " ";
    let h = this.change(date.getHours()) + ":";
    let m = this.change(date.getMinutes()) + ":";
    let s = this.change(date.getSeconds());
    return Y + M + D + h + m + s;
  },
  change(t) {
    if (t < 10) {
      return "0" + t;
    } else {
      return t;
    }
  },
  onDiyFormClose() {
    this.setData({
      showDiyForm: false,
    });
  },
  //获取快递公司
  getCompany() {
    let that = this;
    let urlStr = "";
    if (this.data.orderType == "supplier") {
      urlStr += app.getNetAddresss("plugin.supplier.frontend.order.express-company");
    } else if (this.data.orderType == "subsidiary") {
      urlStr += app.getNetAddresss("plugin.subsidiary.frontend.order.express-company");
    } else if (this.data.orderType == "storeMang") {
      urlStr += app.getNetAddresss("plugin.shop-assistant.frontend.order.expressCompanies");
    } else {
      urlStr += app.getNetAddresss("plugin.store-cashier.frontend.store.center.sendOrder");
    }
    urlStr += "&order_id=" + that.data.order_id;
    app._getNetWork({
      url: urlStr,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          that.setData({
            options: res.data.express_companies ? res.data.express_companies : [],
          });
          var arrayOfSquares = that.data.options.map(function (item) {
            return item.name;
          });
          if (!app._isTextEmpty(res.data.jurisdiction_set)) {
            that.setData({
              jurisdiction_set: res.data.jurisdiction_set,
            });
          }
          that.setData({
            columns: arrayOfSquares,
            addresseeInfo: res.data.address,
            address: res.data.address.address,
            mobile: res.data.address.mobile,
            receiver: res.data.address.realname,
          });
        } else {
          wx.showToast({
            icon: "none",
            title: res.msg,
            duration: 1500,
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  getNetData() {
    let that = this;
    let urlStr = "";
    if (this.data.orderType == "cashier") {
      urlStr += app.getNetAddresss("plugin.store-cashier.frontend.Order.detail");
    } else if (this.data.orderType == "store") {
      urlStr += app.getNetAddresss("plugin.store-cashier.frontend.store.order-detail");
    } else if (this.data.orderType == "supplier") {
      urlStr += app.getNetAddresss("plugin.supplier.frontend.order.detail");
    } else if (this.data.orderType == "subsidiary") {
      urlStr += app.getNetAddresss("plugin.subsidiary.frontend.order.detail");
    } else if (this.data.orderType == "hotel") {
      urlStr += app.getNetAddresss("plugin.hotel.frontend.hotel.detail");
    } else if (this.data.orderType == "hotel_center") {
      urlStr += app.getNetAddresss("plugin.hotel.frontend.hotel.center.order-detail");
    } else if (this.data.orderType == "hotelcashier") {
      urlStr += app.getNetAddresss("plugin.hotel.frontend.Order.detail");
    } else if (this.data.orderType == "lease_toy") {
      urlStr += app.getNetAddresss("plugin.lease-toy.api.order.order-detail.index");
    } else if (this.data.orderType == "yz_lease_toy") {
      urlStr += app.getNetAddresss("plugin.yz-supply-lease.api.order-detail.index");
    } else if (this.data.orderType == "verifier") {
      urlStr += app.getNetAddresss("plugin.package-deliver.frontend.clerk-order-detail.index"); //自提点核销员
    } else if (this.data.orderType == "pdy") {
      urlStr += app.getNetAddresss("plugin.package-delivery.frontend.detail.index"); //商城自提点核销员
    } else if (this.data.orderType == "commission_activity") {
      urlStr += app.getNetAddresss("plugin.commission-activity.api.activity-inquire.order-detail");
    } else if (this.data.orderType == "groups") {
      urlStr += app.getNetAddresss("plugin.fight-groups.frontend.controllers.detail.index");
    } else if (this.data.orderType == "ywmgroups") {
      urlStr += app.getNetAddresss("plugin.ywm-fight-groups.frontend.controllers.detail.index");
    } else if (this.data.orderType == "groupsBuy") {
      urlStr += app.getNetAddresss("plugin.together-purchase.api.index.getTogetherData");
      urlStr += "&art=orderDetail";
    } else if (this.data.orderType == "grabGroup") {
      urlStr += app.getNetAddresss("plugin.snatch-regiment.api.index.getSnatchData");
      urlStr += "&art=orderDetail";
    } else if (this.data.orderType == "pickup_card") {
      urlStr += app.getNetAddresss("plugin.picking-card.frontend.detail");
    } else if (this.data.orderType == "picking-card-one") {
      urlStr += app.getNetAddresss("plugin.picking-card-one.frontend.detail");
    } else if (this.data.orderType == "community_buying") {
      urlStr += app.getNetAddresss("plugin.package-deliver.frontend.order.detail.index");
    } else if(this.data.orderType == "luck-draw"){
      urlStr += app.getNetAddresss("plugin.luck-draw.frontend.index.myPrizeDetail");
    } else if(this.data.orderType == "newRetail"){
      urlStr += app.getNetAddresss("plugin.new-retail.frontend.orderData.detail");
    } else if(this.data.orderType == "zhpGroup"){
      urlStr += app.getNetAddresss("plugin.zhp-group-lottery.frontend.detail.index");
    } else if(this.data.orderType == "storeMang"){
      urlStr += app.getNetAddresss("plugin.shop-assistant.frontend.order.order-detail");
    } else if (this.data.orderType == "warehouseTakeDelivery") {
      urlStr += app.getNetAddresss("plugin.warehouse.frontend.controllers.takeDelivery.order-detail");
    } else if (this.data.orderType == "warehousePurchasing") {
      urlStr += app.getNetAddresss("plugin.warehouse.frontend.controllers.purchasing.order-detail");
    } else if(this.data.orderType == "reserve_simple"){
      urlStr += app.getNetAddresss("plugin.reserve-simple.frontend.reserve-order.get-detail");
    } else if (this.data.orderType == "ysSystem") {
      urlStr += app.getNetAddresss("plugin.ys-system.frontend.history-order.ys-detail");
    } else if (this.data.orderType == "debt"){
      urlStr += app.getNetAddresss("plugin.debt-shop.frontend.order-detail.index");
      urlStr += "&order_id=" + that.data.order_id;
      urlStr += "&member_type=" + that.data.debt_shop_member_type;
    } else if (this.data.orderType == "travelAround") {
      urlStr += app.getNetAddresss("plugin.travel-around.frontend.order.detail");
      urlStr += "&order_id=" + that.data.order_id;
    } else if (this.data.orderType == "yunChat"){
      urlStr += app.getNetAddresss("plugin.yun-chat.frontend.order-detail");
      urlStr += "&order_id=" + that.data.order_id;
    }
     else {
      urlStr += app.getNetAddresss("order.detail");
    }
    if (this.data.is_clerk) {
      urlStr += "&order_id=" + that.data.order_id;
      urlStr += "&is_clerk=" + that.data.is_clerk;
    } else if (this.data.orderType == "commission_activity") {
      urlStr += "&activity_id=" + that.data.order_id;
    } else {
      urlStr += "&order_id=" + that.data.order_id;
    }
    if(this.data.keywork == 'customer'){
      urlStr = app.getNetAddresss('plugin.customer-center.frontend.controllers.customer.order-detail');
      if (this.data.orderType === "shop") {
        urlStr += "&order_type=order";
      } else if (this.data.orderType === "hotel") {
        urlStr += "&order_type=hotel_order";
      } else if (this.data.orderType === "lease_toy") {
        urlStr += "&order_type=lease_order";
      } else if (this.data.orderType === "groups") {
        urlStr += "&order_type=fight_groups_order";
      } else if (this.data.orderType === "grabGroup") {
        urlStr += "&order_type=snatch_regiment_order";
      }
      urlStr += "&order_id="+that.data.order_id;
      urlStr += "&member_id="+that.data.memberId;
    }

    urlStr = app.getNetAddresss(urlStr);
    app._getNetWork({
      url: urlStr,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          let myData = {};
          let form = [];
          if (that.data.orderType == "groupsBuy" || that.data.orderType == "grabGroup") {
            myData = res.data.orderDetail;
          } else {
            myData = res.data;
          }
          if (myData.custom && that.data.is_clerk == 1) {
            form = myData.custom.form;
          }
          if(that.data.orderType == 'supplier'){
            that.setData({
              jurisdiction_set:myData.jurisdiction_set
            })
          }
          if(myData.reserve_date){
            that.setData({
              reserveDate:myData.reserve_date
            });
          }

          that.setData({
            order_data: myData,
            order_pay_id: myData.order_pay_id,
            dispatch_type_id: myData.dispatch_type_id,
            customForm: form,
            custom_receipt_confirmation_html:myData.receipt_goods_notice
          });
          if(myData.aggregation_cps_recharge_bill && !app._isTextEmpty(myData.aggregation_cps_recharge_bill.recharge_number)){
            that.setData({
              aggregation_cps_recharge_bill:myData.aggregation_cps_recharge_bill.recharge_number
            })
          }

          // 话费慢充
          if (myData.phone_bill) {
            that.setData({
              phone_bill: myData.phone_bill,
            });
          }
          // 话费慢充pro
          if (myData.phone_bill_pro) {
            that.setData({
              phone_bill: myData.phone_bill_pro,
            });
          }
          // 电费充值
          if (myData.electricity_bill_pro) {
            that.setData({
              electricity_bill_pro: myData.electricity_bill_pro,
            });
          }
          if(myData.oil_recharge){
            that.setData({
              oil_recharge:myData.oil_recharge
            });
          }
          if (myData.address_info && !myData.address_info.address) {
            that.setData({
              address: myData.address_info.store_address,
              mobile: myData.address_info.member_mobile,
              receiver: myData.address_info.member_realname,
            });
          } else if (myData.address_info) {
            that.setData({
              address: myData.address_info.address,
              mobile: myData.address_info.mobile,
              receiver: myData.address_info.realname,
            });
          } else if (myData.address) {
            that.setData({
              address: myData.address.address,
              mobile: myData.address.mobile,
              receiver: myData.address.realname,
            });
          }
          if(myData.automat){
            that.setData({
              address: '',
              mobile: '',
              receiver:'',
            });
          }
          that.setData({
            pay_type_id: myData.pay_type_id,
          });
          if (that.data.orderType == "hotel") {
            that.setData({
              hotel_start: res.data.hotel_order.enter_at.split(" ")[0],
              hotel_end: res.data.hotel_order.leave_at.split(" ")[0],
              hotel_name: res.data.hotel_order.has_one_hotel.hotel_name,
            });
            that.getDays(that.data.hotel_start, that.data.hotel_end);
          }
          if (myData.dispatch_type_id == 8) {
            that.setData({
              package_deliver: myData.package_deliver,
            });
          }else if(myData.dispatch_type_id == 15){
            that.setData({
              package_deliver: myData.package_delivery,
            });
          }
          if (that.data.orderType == 'travelAround') {
            that.setData({
              travelAroundDetail: myData.travel_around_order,
              aroundOrderDetatil: myData.has_many_travel_around_order_detatil[0] || {}
            })
          }
          if (that.data.orderType == 'sachertorte') {
            that.setData({
              supplyCakeOrder: myData.yz_supply_cake_order,
            })
          }
        } else {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1500,
            success: function () {
              setTimeout(function () {
                //要延时执行的代码
                wx.navigateBack({
                  delta: 1,
                });
              }, 1500); //延迟时间
            },
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  //时间日期
  getDays(strDateStart, strDateEnd) {
    let strSeparator = "-"; //日期分隔符
    let oDate1, oDate2, iDays;
    oDate1 = strDateStart.split(strSeparator);
    oDate2 = strDateEnd.split(strSeparator);
    let strDateS = new Date(oDate1[0], oDate1[1] - 1, oDate1[2]);
    let strDateE = new Date(oDate2[0], oDate2[1] - 1, oDate2[2]);
    iDays = parseInt(Math.abs(strDateS - strDateE) / 1000 / 60 / 60 / 24); //把相差的毫秒数转换为天数
    this.setData({
      night_day: iDays,
    });
  },
  getCpsDetail(goods){
    let urlStr = app.getNetAddresss("plugin.aggregation-cps.api.web.getGoodsUrl");
    app._getNetWork({
      url: urlStr,
      data:{
        goods_id:goods.goods_id
      },
      success: function(resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          wx.navigateTo({
            url: res.data.another_mini_route,
            icon:'none',
            duration:1000
          });
        } else {
          wx.showToast({
            icon: 'none',
            title: res.msg,
            duration: 1500
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  //跳转商品详情页面
  toGoodsDetail(e) {
    let goods = e.currentTarget.dataset.good;
    if(this.data.order_data.plugin_id == '150' || this.data.order_data.plugin_id == '31'||this.data.order_data.plugin_id == '107'){
      //不能跳转
      return;
    }
    if(this.data.order_data.plugin_id == '71'){
      this.getCpsDetail(goods);
      return;
    }
    if(this.data.order_data.deposit_ladder && this.data.order_data.deposit_ladder.activity_id || this.data.order_data.deposit_ladder_dj && this.data.order_data.deposit_ladder_dj.activity_id){
      let activity_id = this.data.order_data.deposit_ladder && this.data.order_data.deposit_ladder.activity_id ? this.data.order_data.deposit_ladder.activity_id : this.data.order_data.deposit_ladder_dj.activity_id;
      //尾款商品跳转详情
      wx.navigateTo({
        url: "/packageH/deposit_group/activity_index/activity_index?id=" + activity_id,
      });
      return;
    }
    if (this.data.order_data.plugin_id == 54) {
      let store_id = null;
      if (goods.store_id && goods.store_id != 0 && goods.store_id != "undefined") {
        store_id = "/" + goods.store_id;
      }

      wx.navigateTo({
        url: "/packageA/detail_v2/detail_v2?id=0" + store_id + "&name=group&fight_groups=" + goods.goods_id,
      });
    } else if(this.data.order_data.plugin_id == 151){
      wx.navigateTo({
        url: "/packageA/detail_v2/detail_v2?id=0" + "&name=ywmGroup&fight_groups=" + goods.goods_id,
      });
    } else if(this.data.order_data.plugin_id == 157){
      wx.navigateTo({
        url: `/packageF/sachertorte/sachertorteGoods/sachertorteGoods?id=${goods.goods_id}`,
      })
    } else if(this.data.order_data.plugin_id == 155){
      //新盲盒
      // wx.navigateTo({
      //   url: "/packageF/new_blind_box/index" ,
      // });
    } else {
      wx.navigateTo({
        url: "/packageA/detail_v2/detail_v2?id=" + goods.goods_id,
      });
    }
  },
  //根据按钮值判断用途
  operation(e) {
    let btn = e.currentTarget.dataset.item;
    let order = e.currentTarget.dataset.orderdata;
    this.setData({
      orderPayId: order.id,
    });
    if (btn.value == 8) {
      this.checklogistics(order, btn);
    } else if (btn.value == 12) {
      this.deleteOrder(order, btn);
    } else if (btn.value == 10) {
      this.comment(order, btn);
    } else if (btn.value == 1 || btn.value == "snatch_regiment_pay") {
      this.toPay(order, btn);
    } else if (btn.value == 13 || btn.value == "snatch_regiment_refund" || btn.value == '54') {
      //退款
      this.getTemplate(order, btn);
    } else if (btn.value == 9) {
      //取消订单
      this.publicMessage(btn, order,'取消此订单');
    } else if (btn.value == 5) {
      //确认订单
      this.confirmOrder(order, btn);
    } else if (btn.value == 18) {
      //退款中
      this.toRefundDetail(order, btn);
    } else if (btn.value == "cashierPay") {
      //订单已付款
      this.cashPayOrder(order, btn);
    } else if (btn.value == "verification_code") {
      //验证核销
      this.verification(order, btn);
    } else if (btn.value == 20) {
      console.log("现金支付");
      //现金付款
      this.verificationCash(order, btn);
    } else if (btn.value == 3) {
      this.gotoRefund(order.id);
    } else if (btn.value == 40) {
      this.gotoRefundCheck(order.id);
    } else if (btn.value == 4) {
      this.gotoMakeSure(order.id);
    } else if (btn.value == 21) {
      this.shopRecord();
    } else if (btn.value == 22) {
      // 确认支付
      this.publicMessage(btn, order,'支付');
    } else if (btn.value == 101) {
      let _url = "/packageE/pickUpCard/pickUpCardReimburse/pickUpCardReimburse?orderid=" + order.id;
      if(this.data.orderType == "picking-card-one" || order.plugin_id == 95) _url = _url + '&plugin=one';
      wx.navigateTo({
        url: _url
      });
    } else if (btn.value == 23 || btn.value == 60) {
      // 确认发货
      if (order.dispatch_type_id == 3) {
        this.sendGoogs();
      } else {
        this.getCompany();
        this.setData({
          dialogVisible: true,
        });
      }
    } else if (btn.value == 24 || btn.value == 61) {
      //取消发货
      this.publicMessage(btn, order,'取消发货');
    } else if (btn.value == 25) {
      //确认收货
      this.publicMessage(btn, order,'收货');
    } else if (btn.value == 26) {
      //关闭订单
      this.publicMessage(btn, order,'关闭订单');
    } else if (btn.value == 27) {
      this.evaluate(btn, order);
    } else if (btn.value == 28) {
      //卡密
      this.truckList(btn, order);
    } else if (btn.value == 41) {
      this.getKefu();
    } else if (btn.value == 50) {
      //发票
      this.checkInvoice(btn, order);
    } else if (btn.value == 51) {
      //聚合cps
      if (order.plugin_id == "71") {
        wx.navigateTo({
          url: "/packageH/cpsPwd/cpsPwd?id=" + order.id,
        });
      }
    }else if (btn.value == 56) {
      //* 门店核销
      wx.navigateTo({
        url: "/packageH/project_verification/MyProject/MyProject",
      });
    } else if (btn.value == "coupon") {
      //分享优惠券
      wx.navigateTo({
        url: "/packageD/coupon_share/coupon_share?orderid=" + order.id,
      });
    } else if (btn.value == "lease_toy_refund" || btn.value == "package_deliver_clerk" || btn.value == "package_delivery_confirm") {
      this.publicMessage(btn, order,'此操作');
    } else if (btn.value == "lease_toy_apply_adopt") {
      wx.navigateTo({
        url: "/packageB/member/OrderReturn/OrderReturn?id=" + order.id,
      });
    } else if (btn.value == "lease_toy_return_info") {
      // 归还详情
      wx.navigateTo({
        url: "/packageA/others/order_ruturn_info/order_ruturn_info?id=" + order.id,
      });
    } else if (this.isConfirmWriteOff(btn.value)) {
      // 自提点核销
      this.getQrImg(btn, order);
    } else if (btn.value == "snatch_regiment_barter") {
      // 抢团易货兑换
      this.setData({
        showBarter: true,
        showBarter_value: order.barter,
      });
    } else if(btn.value == 53){
      this.getBlindBoxGoods(order.id);
    } else if (btn.value == "close_reason") {
      this.setData({
        refundShow: true,
        refundText: order.close_reason
      });
    } else if(btn.value == 140){
      wx.navigateTo({
        url:"/packageI/brand_resources/cardVoucherInfo/cardVoucherInfo?id="+order.id
      });
    } else if(btn.value == "city_delivery_detail"){
      wx.navigateTo({
        url:"/packageA/member/order/orderLogisticsDetails/orderLogisticsDetails?id="+order.id
      });
    } else if (btn.value == "inventory_apply") {
      this.getWarehouseList_CH(); //获取仓库列表(申请存货)
    } else if (btn.value == 'coffee_store_code_list'){
      wx.navigateTo({
        url: '../../../packageJ/coffee_machine/coffee_machine_verification/coffee_machine_verification?order_id=' + order.id,
      })
    } else if(order.plugin_id == 155) { 
      //新盲盒
      if (btn.value == "new_blind_box_unpacking") { // 新盲盒商品-去开箱
        wx.navigateTo({
          url:"/packageF/new_blind_box/blindBox/index?order_id="+order.id
        });
      } else if (btn.value == "new_blind_box_goods") { // 新盲盒商品-未点发货或兑换
        this.setData({
          overlayShow: true,
          newBlindBoxData: {
            api: btn.api,
            order_id: order.id
          }
        })
      } else if (btn.value == "new_blind_box_exchange_order") { // 新盲盒商品-兑换积分
        this.setData({
          drawShow: true,
          drawType: 2,
          newBlindBoxData: {
            api: btn.api,
            order_id: order.id
          }
        })
      } else if (btn.value == "new_blind_box_sub_order") { // 新盲盒商品-已兑换
        this.setData({
          drawShow: true,
          drawType: 1,
          newBlindBoxData: {
            api: btn.api,
            order_id: order.id
          }
        })
      }
    } else {
      this.publicMessage(btn, order);
    }
  },
  onCloseRefundShow(){
    this.setData({
      refundShow: false
    });
  },
  //周边游的预约链接
  subscribeOn(event) {
    let codeUrl = event.currentTarget.dataset.codeurl;
    wx.navigateTo({
      url: '../../../packageF/tourAround/out/out?src='+ codeUrl,
    })
  },

  // 点击盲盒商品
  goOrderList(item){
    console.log(item);
    let id = item.currentTarget.dataset.item.id;
    let orderType = this.data.orderType;
    wx.navigateTo({
      url: '/packageA/member/orderdetail/orderdetail?order_id=' + id + '&orderType=' + orderType
    });
  },
  // 盲盒商品弹窗
  getBlindBoxGoods(){
    let that = this;
    let urlStr = app.getNetAddresss('plugin.blind-box.api.index.blind-box-goods');
    urlStr += '&order_id=' + this.data.orderPayId;
    app._getNetWork({
      url: urlStr,
      success: function(resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          that.setData({
            ['blindBoxInfo.show']:true,
            ['blindBoxInfo.goods']:res.data.order
          });
        } else {
          wx.showToast({
            icon: 'none',
            title: res.msg,
            duration: 1200
          });
        }
      },
      fail: function(res) {
        console.log(res);
      }
    });
  },
  blindBoxInfoTap(e){
    this.setData({
      ['blindBoxInfo.show']:false,
    });
  },
  //按钮公共方法，点击提示框进行操作，确认后刷新
  publicMessage(btn, order) {
    let that = this;
    if (!btn.api) {
      return;
    }
    wx.showModal({
      title: "提示",
      content: `确定${btn.name}?`,
      success(res) {
        if (res.confirm) {
          let urlStr = "";
          urlStr += app.getNetAddresss(btn.api);
          urlStr += "&order_id=" + order.id;
          app._getNetWork({
            url: urlStr,
            success: function (resdata) {
              var res = resdata.data;
              if (res.result == 1) {
                that.getNetData();
                wx.showToast({
                  title: `${btn.name}成功`,
                  icon: "success",
                  duration: 1500,
                  success: function () {
                    setTimeout(function () {
                      //要延时执行的代码
                      wx.navigateBack({
                        delta: 1,
                      });
                    }, 1500); //延迟时间
                  },
                });
              } else {
                wx.showToast({
                  icon: "none",
                  title: res.msg,
                  duration: 1000,
                });
              }
            },
            fail: function (res) {
              console.log(res);
            },
          });
        }
      },
    });
  },
  isConfirmWriteOff(value){
    // 是否为确认核销按钮
    const _ARR = ["store_package_deliver_clerk_confirm","package_deliver", "package_delivery_confirm_code", "store_package_deliver", "reserve_simple"];
    if (_ARR.indexOf(value) > -1) return true;
  },
  // 自提点确认核销
  getQrImg(btn, order) {
    let urlStr = app.getNetAddresss(btn.api);
    if(btn.value == "reserve_simple"){
      urlStr += "&id=" + order.id;
    } else {
      urlStr += "&order_id=" + order.id;
    }
    app._getNetWork({
      url: urlStr,
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          if(btn.value == "store_package_deliver_clerk_confirm"){
            this.getNetData();
            return
          }
          if(res.data.qr_code_url){
            this.setData({
              showQrcode: true,
              qrcode_url: res.data.qr_code_url,
            });
          }
        } else {
          wx.showToast({
            icon: "none",
            title: res.msg,
            duration: 1000,
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  onClose() {
    this.setData({
      showQrcode: false,
    });
  },

  //查看物流
  checklogistics(item, btn) {
    //logistics
    if (item.is_all_send_goods == 0) {
      wx.navigateTo({
        url: "/packageA/member/order/logistics/logistics?id=" + item.id + "&api=" + btn.api,
      });
    } else {
      wx.navigateTo({
        url: "/packageE/multiplePackages/multiplePackages?id=" + item.id + "&api=" + btn.api,
      });
    }
  },
  //删除订单
  deleteOrder(item, btn, orderidx) {
    let that = this;
    wx.showModal({
      title: "提示",
      content: "确定删除此订单?",
      success(res) {
        if (res.confirm) {
          //删除当前选中的地址
          that.sentRequest(btn.api, "&order_id=" + item.id, false);
        }
      },
    });
  },
  //确认发货
  sendGoogs(event) {
    if (!event || event.detail === "confirm") {
      let that = this;
      if (this.data.orderType == "supplier") {
        let urlStr = "";
        urlStr += app.getNetAddresss("plugin.supplier.frontend.order.send");
        let json = {
          order_id: that.data.orderPayId,
          express_code: that.data.expressName.value,
          express_company_name: that.data.expressName.name,
          express_sn: that.data.numberName,
        };
        app._postNetWork({
          url: urlStr,
          showToastIn: false,
          data: json,
          success: function (resdata) {
            var res = resdata.data;
            that.setData({
              dialogVisible: false,
            });
            if (res.result == 1) {
              that.getNetData();
              that.triggerEvent("stoprefresh", false);
              that.triggerEvent("ConfrimOrderNotification", "pay");
              wx.showToast({
                icon: "success",
                title: "发货成功",
                duration: 1000,
              });
            } else{
              app.tips(res.msg);
            }
          },
          fail: function (res) {
            app.tips(res);
          },
        });
      } else if (this.data.orderType == "subsidiary"||this.data.orderType == "storeMang") {
        let urlStr = "";
        urlStr = app.getNetAddresss("plugin.subsidiary.frontend.order.send");
        if(this.data.orderType == "storeMang"){
          urlStr = app.getNetAddresss("plugin.shop-assistant.frontend.order.send");
        }
        let json = {
          order_id: that.data.orderPayId,
          express_code: that.data.expressName.value,
          express_company_name: that.data.expressName.name,
          express_sn: that.data.numberName,
        };
        app._postNetWork({
          url: urlStr,
          showToastIn: false,
          data: json,
          success: function (resdata) {
            var res = resdata.data;
            if (res.result == 1) {
              that.setData({
                dialogVisible: false,
              });
              that.getNetData();
              that.triggerEvent("stoprefresh", false);
              that.triggerEvent("ConfrimOrderNotification", "pay");
              wx.showToast({
                icon: "success",
                title: "发货成功",
                duration: 1000,
              });
            }
          },
          fail: function (res) {},
        });
      } else {
        let urlStr = "";
        urlStr += app.getNetAddresss("plugin.store-cashier.frontend.store.center.order-operation.send");
        urlStr += "&order_id=" + that.data.orderPayId;
        urlStr += "&express_code=" + that.data.expressName.value;
        urlStr += "&express_company_name=" + that.data.expressName.name;
        urlStr += "&express_sn=" + that.data.numberName;
        app._getNetWork({
          url: urlStr,
          success: function (resdata) {
            var res = resdata.data;
            if (res.result == 1) {
              that.triggerEvent("ConfrimOrderNotification", "pay");
              that.getNetData();
              wx.showToast({
                icon: "success",
                title: "发货成功",
                duration: 1000,
              });
              that.setData({
                dialogVisible: false,
              });
            }
          },
          fail: function (res) {
            console.log(res);
          },
        });
      }
    } else {
      this.setData({
        dialogVisible: false,
      });
      this.triggerEvent("stoprefresh", false);
    }
  },
  //快递选择
  seleRegional: function () {
    this.setData({
      dateshow_1: true,
    });
  },
  onCancelbtn: function () {
    this.setData({
      dateshow_1: false,
      inputExpressCompanyName: "",
      filterExpressCompanys: [],
    });
  },
  onConfirmbtn: function (e) {
    let index = e.detail.index;
    let val = e.detail.value;
    let array = this.data.options;
    this.setData({
      dateshow_1: false,
      regional: val,
      expressName: array[index],
      inputExpressCompanyName: "",
      filterExpressCompanys: [],
    });
  },
  sentRequest(action, params, isIndicator) {
    let urlStr = app.getNetAddresss(action);
    urlStr += params;
    app._getNetWork({
      url: urlStr,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1500,
            success: function () {
              setTimeout(function () {
                //要延时执行的代码
                wx.navigateBack({
                  delta: 1,
                });
              }, 1500); //延迟时间
            },
          });
        } else {
          wx.showToast({
            icon: "none",
            title: res.msg,
            duration: 1000,
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  //评价订单
  comment(item, btn) {
    // 跳到评价订单
    //comment    order: item
    wx.navigateTo({
      url: "/packageB/member/comment/comment?order=" + JSON.stringify(item ? item : {}),
    });
  },
  toPay(item, btn) {
    //status-2合并支付 type-1订单支付
    wx.navigateTo({
      url: "/packageD/buy/orderPay/orderPay?order_id=" + item.id + "&status=2" + "&api=" + btn.api,
    });
  },
  //获取模板id
  getTemplate(order, btn) {
    let urlStr = app.getNetAddresss("member.member.getMiniTemplateCorrespond");
    let that = this;
    app._getNetWork({
      url: urlStr,
      data: {
        small_type: 2,
      },
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          let array = [];
          for (let i = 0; i < res.data.length; i++) {
            array.push(res.data[i].template_id);
          }
          that.setData({
            TemplateArray: array,
          });
          wx.requestSubscribeMessage({
            tmplIds: that.data.TemplateArray,
            success(res) {
              that._toRefund(order, btn);
            },
            fail() {
              that._toRefund(order, btn);
            },
          });
        } else {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1500,
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  //退款
  _toRefund(item, btn) {
    console.log(btn.value);
    //refund
    if(this.data.order_data.plugin_id  == 107){
      wx.navigateTo({
        url: "/packageD/member/myOrder/refund/refund?order_id=" + item.id + "&type=1"+'&value='+btn.value,
      });
      return;
    }
    if(item.plugin_id == '154'){
      wx.navigateTo({
        url: `/packageD/member/myOrder/refund/refund?order_id=${item.travel_around_order?.order_id}&type=4&value=${btn.value}&pluginid=${item.plugin_id}`
      });
      return;
    }
    if (btn.value == "snatch_regiment_refund") {
      //抢团
      wx.navigateTo({
        url: "/packageD/member/myOrder/refund/refund?order_id=" + item.id + "&type=3",
      });
    } else {
      wx.navigateTo({
        url: "/packageD/member/myOrder/refund/refund?order_id=" + item.id + "&type=1",
      });
    }
  },

  //确认收货
  confirmOrder(item, btn) {
    if((item.plugin_id==0 || item.plugin_id==44) && this.data.custom_receipt_confirmation_html!==''){
      this.setData({
        custom_receipt_confirmation_btn:btn,
        custom_receipt_confirmation_item:item,
        custom_receipt_confirmation_show:true
      });
      return;
    }
    wx.showModal({
      title: "提示",
      content: "您确定收到货物?",
      success:(res)=> {
        if (res.confirm) {
          this._confirmOrder_request(item,btn);
        }
      },
    });
  },
  CustomReceiptConfirmationSend(){
    this._confirmOrder_request(this.data.custom_receipt_confirmation_item,this.data.custom_receipt_confirmation_btn);
  },
  _confirmOrder_request(item,btn){
    let urlStr = app.getNetAddresss(btn.api);
    urlStr += "&order_id=" + item.id;
    app._getNetWork({
      url: urlStr,
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          app.tips(res.msg);
          if(item.is_boss){
            // is_boss：true是店长,店长跳转门店订单列表页
            wx.navigateTo({url: "/packageA/member/myOrder_v2/myOrder_v2?status=0&orderType=store"});
            return
          }
          this.getNetData();
        } else {
          app.tips(res.msg);
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  //退款中
  toRefundDetail(item, btn) {
    if(item.plugin_id == 154){
      wx.navigateTo({
        url: `/packageD/member/myOrder/Aftersales/Aftersales?refund_id=${item.travel_around_refund?.id}&pluginid=${item.plugin_id}`,
      });
    } else {
      wx.navigateTo({
        url: "/packageD/member/myOrder/Aftersales/Aftersales?refund_id=" + item.refund_id,
      });
    }
  },
  cashPayOrder(item, btn) {
    let that = this;
    wx.showModal({
      title: "提示",
      content: "确定此订单已付款?",
      success(res) {
        if (res.confirm) {
          that.sentRequest(btn.api, "&order_id=" + item.id + "&order_pay_id=" + that.data.order_pay_id, false);
        }
      },
    });
  },
  verification(item, btn) {
    //订单核销
    //orderVerification
    wx.navigateTo({
      url: "/packageD/member/myOrder/orderVerification/orderVerification?order_id=" + item.id + "&api=" + btn.api,
    });
  },
  verificationCash(item, btn) {
    let that = this;
    wx.showModal({
      title: "提示",
      content: "确定此订单已付款?",
      success(res) {
        if (res.confirm) {
          that.HxsentRequest(btn.api, "&order_id=" + item.id + "&order_pay_id=" + that.data.order_pay_id, false);
        }
      },
    });
  },
  // 确认核销
  HxsentRequest(action, params, isIndicator) {
    let urlStr = app.getNetAddresss(action);
    urlStr += params;
    app._getNetWork({
      url: urlStr,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1500,
            success: function () {
              setTimeout(function () {
                //要延时执行的代码
                wx.reLaunch({
                  url: "/packageG/index/index",
                });
              }, 1500); //延迟时间
            },
          });
        } else {
          wx.showToast({
            icon: "none",
            title: res.msg,
            duration: 1000,
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  //退还跳转
  gotoRefund(val) {
    wx.navigateTo({
      url: "/packageB/member/OrderReturn/OrderReturn?id=" + val,
    });
  },
  //退还跳转
  gotoRefundCheck(val) {
    wx.navigateTo({
      url: "/packageB/member/OrderReturnCheck/OrderReturnCheck?id=" + val,
    });
  },
  //待确定
  gotoMakeSure(val) {
    wx.navigateTo({
      url: "/packageB/member/OrderReturnSure/OrderReturnSure?id=" + val,
    });
  },
  //汇款记录
  shopRecord(val) {
    wx.navigateTo({
      url: "/packageB/member/OrderRecord/OrderRecord?order_id=" + val + "&order_state=" + this.data.order_data.status_name,
    });
  },

  // 评价
  evaluate(order, btn) {
    //抢单评价
    //DeliveryEvaluate
    wx.navigateTo({
      url: "/packageD/member/myOrder/DeliveryEvaluate/DeliveryEvaluate?order_id=" + order.order_id + "&api=" + btn.api + "&name=distributor",
    });
  },
  //卡密
  truckList(btn, order) {
    //TruckList
    wx.navigateTo({
      url: "/packageD/member/myOrder/truckList/truckList?order_id=" + order.id,
    });
  },
  //查看发票
  checkInvoice(btn, order) {
    //Invoice
    wx.navigateTo({
      url: "/packageD/member/myOrder/invoice/invoice?order_id=" + order.id,
    });
  },
  numberNamebtn(e) {
    let val = e.detail.value;
    this.setData({
      numberName: val.trim(),
    });
  },
  goToAdress() {
    let latitude = this.data.package_deliver.lat;
    let longitude = this.data.package_deliver.lng;
    let store_name = this.data.package_deliver.deliver_name || this.data.package_deliver.buyer_name;
    let point = app.BMapTransqqMap(parseFloat(longitude), parseFloat(latitude));
    wx.openLocation({
      latitude: point.lat,
      longitude: point.lng,
      scale: 18,
      name: store_name,
    });
  },

  // 评价，追评，查看评价按钮
  evaluateOpration(e) {
    let btn = e.target.dataset.btn;
    let item = e.target.dataset.goods;
    let order_id = e.target.dataset.order.id;
    //value-0评价 value-1追加评价 value-2查看评价详情
    if (btn.value == 0) {
      wx.navigateTo({
        url: '/packageD/member/evaluate/evaluate?order_id=' + order_id + '&id=' + item.id
      });
    } else if (btn.value == 1) {
      wx.navigateTo({
        url: '/packageD/member/addevaluate/addevaluate?order_id=' + order_id + '&item=' + JSON.stringify(item)
      });
    } else if (btn.value == 2) {
      let options = "?order_id=" + order_id;
      options = options + '&goods_id=' + item.has_one_comment.goods_id;
      options = options + '&comment_id=' + item.has_one_comment.id;
      options = options + '&order_goods_id=' + item.id;
      wx.navigateTo({
        url: '/packageD/member/CommentDetails/CommentDetails' + options
      });
    }
  },

  onChangeInventoryApplyRadio(event){
    this.setData({
      inventoryApplyRadio: event.detail,
    });
  },
  // ‘申请存货’获取仓库列表
  getWarehouseList_CH() {
    let urlStr = app.getNetAddresss("plugin.order-inventory.frontend.index.warehouse-list");
    app._postNetWork({
      url: urlStr,
      data: {},
      success: (resdata) => {
        let res = resdata.data;
        if (res.result == 1) {
          this.setData({
            inventoryApplyList: res.data.list, //仓库列表
            inventoryApplyRadio: res.data.list[0].id,
            inventoryApplyPopup: true //存货申请弹窗
          })
        } else {
          app.tips(res.msg)
        }
      }
    });
  },
  // 确认已选择仓库申请仓库
  confirmInventoryApply() {
    let urlStr = app.getNetAddresss("plugin.order-inventory.frontend.index.inventory-apply");
    app._postNetWork({
      url: urlStr,
      data: { warehouse_id: this.data.inventoryApplyRadio, order_id: this.data.orderPayId },
      success: (resdata) => {
        let res = resdata.data;
        app.tips(res.msg)
        if (res.result == 1) {
          this.getNetData();
        }
      }
    });
  },
  //关闭新盲盒商品 - 弹窗
  issueGoodsClose() {
    this.setData({
      overlayShow: false
    })
  },
  drawGoodsClose() {
    this.setData({
      drawShow: false
    })
  },
  filterExpressCompany(event) {
    let input = event.detail;
    const columns = this.data.columns;
    this.setData({
      filterExpressCompanys: columns.filter((val) => {
        return val.indexOf(input) !== -1;
      }),
      inputExpressCompanyName: input,
    });
  },
});
